package com.godpaper.the2tigers.busniess.factorys
{
	import assets.EmbedAssets;
	import com.godpaper.the2tigers.model.BoardModel;
	import com.godpaper.the2tigers.model.PiecesModel;
	import com.godpaper.the2tigers.util.NumberUtil;
	import com.godpaper.the2tigers.views.ChessBoard;
	import com.godpaper.the2tigers.views.components.GasketButton;
	import com.godpaper.the2tigers.views.components.PieceButton;
	
	import de.polygonal.ds.GraphArc;
	import de.polygonal.ds.GraphNode;
	
	import mx.collections.ArrayCollection;
	import mx.core.IFlexDisplayObject;

	/**
	 * 
	 * A ButtonFactory providering PiecesButton and GasketButton
	 * 
	 */	
	public class ButtonFactory
	{
		private static var chessBoard:ChessBoard;
		private static var iPieceButton:IFlexDisplayObject;
		
		public static const FLAG_RED:String = "red";
		public static const FLAG_BLUE:String = "blue";
		public static const MAX_PIECE_NUM_DOGS:int = 16;
		public static const MAX_PIECE_NUM_TIGERS:int = 2;
		public static const MAX_GASKET_NUM:int = 25;
		public static const TYPE_PIECE:String = "pieceButton";
		public static const TYPE_GASKET:String = "gasketButton";
		
		public function ButtonFactory()
		{
			//TODO: implement function
		}
		
		public static function produce(type:String, boardTarget:ChessBoard,flagColor:String=null):void
		{
			//restore board;
			chessBoard = boardTarget;
			switch(type)
			{
				case TYPE_PIECE:
					if(flagColor==FLAG_RED)
					{
						//Postive RED(tigers)
						for(var i:int=0;i<MAX_PIECE_NUM_TIGERS;i++)
						{
							var pieceButtonRED:PieceButton = new PieceButton(); 
							pieceButtonRED.styleName = PieceButton.BUTTON_STYLE_NAME_RED;
							pieceButtonRED.name = pieceButtonRED.pieceVO.name = PieceButton.NAME_PREFIX_RED.concat(i.toString());
							pieceButtonRED.label = i.toString();
							pieceButtonRED.enabled = false;
							if(!BoardModel.getInstance().WITH_DEBUG)
							{
								pieceButtonRED.setStyle("icon",EmbedAssets.ICON_TIGER);
							}

							pieceButtonRED.x = chessBoard.PADDING+chessBoard.GRID_SIZE*(1+2*i)-pieceButtonRED.width/2;
							pieceButtonRED.y = chessBoard.PADDING+chessBoard.GRID_SIZE*2-pieceButtonRED.height/2;
							pieceButtonRED.pieceVO.position = [1+2*i,2];
							BoardModel.getInstance().gamePosition.sett(1+2*i,2,new ArrayCollection([pieceButtonRED]));
							
							//add to chessBoard
							chessBoard.addChild(pieceButtonRED);
							//push to collection;
							PiecesModel.getInstance().redPiecesCollection.addItem(pieceButtonRED);
						}
						
					}else
					{
						//Nagetive BLUE(dogs)
						for(var j:int=0;j<MAX_PIECE_NUM_DOGS;j++)
						{
							var pieceButtonBLUE:PieceButton = new PieceButton();
							pieceButtonBLUE.styleName = PieceButton.BUTTON_STYLE_NAME_BLUE;
							pieceButtonBLUE.name = pieceButtonBLUE.pieceVO.name = PieceButton.NAME_PREFIX_BLUE.concat(j.toString());
							pieceButtonBLUE.label = j.toString();
//							pieceButtonBLUE.enabled = false;
							if(!BoardModel.getInstance().WITH_DEBUG)
							{
								pieceButtonBLUE.setStyle("icon",EmbedAssets.ICON_DOG);
							}	
							var pieceButtonBLUEs:ArrayCollection = new ArrayCollection();
							//position pieceButtonBlue
							if(j<=3)
							{
								pieceButtonBLUE.x = chessBoard.PADDING+chessBoard.GRID_SIZE-pieceButtonBLUE.width/2;
								pieceButtonBLUE.y = chessBoard.PADDING+chessBoard.GRID_SIZE-pieceButtonBLUE.height/2;
								pieceButtonBLUE.pieceVO.position = [1,1];
								if(BoardModel.getInstance().gamePosition.gett(1,1)==null)
								{
									pieceButtonBLUEs.addItem(pieceButtonBLUE);
									BoardModel.getInstance().gamePosition.sett(1,1,pieceButtonBLUEs);
								}else
								{
									(BoardModel.getInstance().gamePosition.gett(1,1) as ArrayCollection).addItem(pieceButtonBLUE);
								}
							}else if(j>3&&j<=7)
							{
								pieceButtonBLUE.x = chessBoard.PADDING+chessBoard.GRID_SIZE*3-pieceButtonBLUE.width/2;
								pieceButtonBLUE.y = chessBoard.PADDING+chessBoard.GRID_SIZE-pieceButtonBLUE.height/2;
								pieceButtonBLUE.pieceVO.position = [3,1];
								if(BoardModel.getInstance().gamePosition.gett(3,1)==null)
								{
									pieceButtonBLUEs.addItem(pieceButtonBLUE);
									BoardModel.getInstance().gamePosition.sett(3,1,pieceButtonBLUEs);
								}else
								{
									(BoardModel.getInstance().gamePosition.gett(3,1) as ArrayCollection).addItem(pieceButtonBLUE);
								}
							}else if(j>7&&j<=11)
							{
								pieceButtonBLUE.x = chessBoard.PADDING+chessBoard.GRID_SIZE-pieceButtonBLUE.width/2;
								pieceButtonBLUE.y = chessBoard.PADDING+chessBoard.GRID_SIZE*3-pieceButtonBLUE.height/2;
								pieceButtonBLUE.pieceVO.position = [1,3];
								if(BoardModel.getInstance().gamePosition.gett(1,3)==null)
								{
									pieceButtonBLUEs.addItem(pieceButtonBLUE);
									BoardModel.getInstance().gamePosition.sett(1,3,pieceButtonBLUEs);
								}else
								{
									(BoardModel.getInstance().gamePosition.gett(1,3) as ArrayCollection).addItem(pieceButtonBLUE);
								}
							}else
							{
								pieceButtonBLUE.x = chessBoard.PADDING+chessBoard.GRID_SIZE*3-pieceButtonBLUE.width/2;
								pieceButtonBLUE.y = chessBoard.PADDING+chessBoard.GRID_SIZE*3-pieceButtonBLUE.height/2;
								pieceButtonBLUE.pieceVO.position = [3,3];
								if(BoardModel.getInstance().gamePosition.gett(3,3)==null)
								{
									pieceButtonBLUEs.addItem(pieceButtonBLUE);
									BoardModel.getInstance().gamePosition.sett(3,3,pieceButtonBLUEs);
								}else
								{
									(BoardModel.getInstance().gamePosition.gett(3,3) as ArrayCollection).addItem(pieceButtonBLUE);
								}
							}
							
							//add to chessBoard
							chessBoard.addChild(pieceButtonBLUE);
							//push to collection;
							PiecesModel.getInstance().bluePiecesCollection.addItem(pieceButtonBLUE);
						}
						trace("initialized gamePosition:",BoardModel.getInstance().gamePosition.dump());
					}
					break;
				case TYPE_GASKET:
					for(var ii:int=0;ii<MAX_GASKET_NUM;ii++)
					{
						var gasketButton:GasketButton = new GasketButton();
						gasketButton.name = GasketButton.NAME_PREFIX.concat(ii.toString());
						gasketButton.label = ii.toString();
						var gasketNode:GraphNode;
						var gasketArc:GraphArc;
						
						gasketButton.x = chessBoard.PADDING+chessBoard.GRID_SIZE*(ii%5) -gasketButton.width/2;
						gasketButton.y = chessBoard.PADDING+chessBoard.GRID_SIZE*(int(ii/5))-gasketButton.height/2;
						gasketButton.position = [ii%5,int(ii/5)];
						gasketNode = new GraphNode(gasketButton);
						BoardModel.getInstance().gameGraph.addNode(gasketNode,ii);
						BoardModel.getInstance().gasketsPosition.sett(ii%5,int(ii/5),gasketButton);
						
						chessBoard.rawChildren.addChild(gasketButton);
						PiecesModel.getInstance().gasketCollection.addItem(gasketButton);
						
					}	
					trace("initialized gasketPosition:",BoardModel.getInstance().gasketsPosition.dump());
					//connect nodes with arc,and set gasketButtons relationship 
					
					//0[0,0] 3
						//right
					BoardModel.getInstance().gameGraph.addArc(0,1,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,0) as GasketButton).right = 
						BoardModel.getInstance().gasketsPosition.gett(1,0);
						//lowerRight	
					BoardModel.getInstance().gameGraph.addArc(0,6,1);	
					(BoardModel.getInstance().gasketsPosition.gett(0,0) as GasketButton).lowerRight = 
						BoardModel.getInstance().gasketsPosition.gett(1,1);	
						//bottom	
					BoardModel.getInstance().gameGraph.addArc(0,5,1);	
					(BoardModel.getInstance().gasketsPosition.gett(0,0) as GasketButton).bottom = 
						BoardModel.getInstance().gasketsPosition.gett(0,1);	
						
					//1[1,0] 3
						//left
					BoardModel.getInstance().gameGraph.addArc(1,0,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,0) as GasketButton).left = 
						BoardModel.getInstance().gasketsPosition.gett(0,0);
						//bottom
					BoardModel.getInstance().gameGraph.addArc(1,6,1);	
					(BoardModel.getInstance().gasketsPosition.gett(1,0) as GasketButton).bottom = 
						BoardModel.getInstance().gasketsPosition.gett(1,1);	
						//right	
					BoardModel.getInstance().gameGraph.addArc(1,2,1);		
					(BoardModel.getInstance().gasketsPosition.gett(1,0) as GasketButton).right = 
						BoardModel.getInstance().gasketsPosition.gett(2,0);	
						
					//2[2,0] 5
						//left
					BoardModel.getInstance().gameGraph.addArc(2,1,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,0) as GasketButton).left = 
						BoardModel.getInstance().gasketsPosition.gett(1,0);	
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(2,6,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,0) as GasketButton).lowerLeft = 
						BoardModel.getInstance().gasketsPosition.gett(1,1);	
						//bottom
					BoardModel.getInstance().gameGraph.addArc(2,7,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,0) as GasketButton).bottom = 
						BoardModel.getInstance().gasketsPosition.gett(2,1);	
						//lowerRight
					BoardModel.getInstance().gameGraph.addArc(2,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,0) as GasketButton).lowerRight = 
						BoardModel.getInstance().gasketsPosition.gett(3,1);	
						//right
					BoardModel.getInstance().gameGraph.addArc(2,3,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,0) as GasketButton).right = 
						BoardModel.getInstance().gasketsPosition.gett(3,0);	
					
					//3[3,0] 3
						//left
					BoardModel.getInstance().gameGraph.addArc(3,2,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,0) as GasketButton).left = 
						BoardModel.getInstance().gasketsPosition.gett(2,0);	
						//bottom
					BoardModel.getInstance().gameGraph.addArc(3,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,0) as GasketButton).bottom = 
						BoardModel.getInstance().gasketsPosition.gett(3,1);
						//right
					BoardModel.getInstance().gameGraph.addArc(3,4,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,0) as GasketButton).right = 
						BoardModel.getInstance().gasketsPosition.gett(4,0);
					
					//4[4,0] 2
						//left
					BoardModel.getInstance().gameGraph.addArc(4,3,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,0) as GasketButton).left = 
						BoardModel.getInstance().gasketsPosition.gett(3,0);
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(4,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,0) as GasketButton).lowerLeft = 
						BoardModel.getInstance().gasketsPosition.gett(3,1);		
						//bottom		
					BoardModel.getInstance().gameGraph.addArc(4,9,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,0) as GasketButton).bottom = 
						BoardModel.getInstance().gasketsPosition.gett(4,1);	
						
					//5[0,1]	3					
						//bottom
					BoardModel.getInstance().gameGraph.addArc(5,10,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,1) as GasketButton).bottom = 
						BoardModel.getInstance().gasketsPosition.gett(0,2);	
						//right
					BoardModel.getInstance().gameGraph.addArc(5,6,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,1) as GasketButton).right = 
						BoardModel.getInstance().gasketsPosition.gett(1,1);		
						//top
					BoardModel.getInstance().gameGraph.addArc(5,0,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,1) as GasketButton).top = 
						BoardModel.getInstance().gasketsPosition.gett(0,0);	
					
					//6[1,1] 8
						//left
					BoardModel.getInstance().gameGraph.addArc(6,5,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(0,1);
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(6,10,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).lowerLeft = 
					BoardModel.getInstance().gasketsPosition.gett(0,2);	
						//bottom
					BoardModel.getInstance().gameGraph.addArc(6,11,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(1,2);		
						//lowerRight
					BoardModel.getInstance().gameGraph.addArc(6,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).lowerRight = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);		
						//right
					BoardModel.getInstance().gameGraph.addArc(6,7,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(2,1);		
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(6,2,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(2,0);		
						//top
					BoardModel.getInstance().gameGraph.addArc(6,1,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(1,0);		
						//upperLeft		
					BoardModel.getInstance().gameGraph.addArc(6,0,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,1) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(0,0);		
					
					//7[2,1] 4
						//left
					BoardModel.getInstance().gameGraph.addArc(7,6,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,1) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(1,1);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(7,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,1) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);		
						//right
					BoardModel.getInstance().gameGraph.addArc(7,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,1) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(3,1);		
						//top
					BoardModel.getInstance().gameGraph.addArc(7,2,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,1) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(2,0);		
					
					//8 [3,1] 8
						//left
					BoardModel.getInstance().gameGraph.addArc(8,7,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(2,1);		
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(8,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).lowerLeft = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(8,13,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(3,2);			
						//lowerRight
					BoardModel.getInstance().gameGraph.addArc(8,14,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).lowerRight = 
					BoardModel.getInstance().gasketsPosition.gett(4,2);			
						//right
					BoardModel.getInstance().gameGraph.addArc(8,9,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(4,1);			
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(8,4,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(4,0);			
						//top
					BoardModel.getInstance().gameGraph.addArc(8,3,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(3,0);			
						//upperLeft	
					BoardModel.getInstance().gameGraph.addArc(8,2,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,1) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(2,0);			
					
					//9 [4,1] 3
						//left
					BoardModel.getInstance().gameGraph.addArc(9,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,1) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(3,1);			
						//bottom
					BoardModel.getInstance().gameGraph.addArc(9,14,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,1) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(4,2);	
						//top
					BoardModel.getInstance().gameGraph.addArc(9,4,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,1) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(4,0);	
					
					//10 [0,2] 5
						//bottom
					BoardModel.getInstance().gameGraph.addArc(10,15,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,2) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(0,3);	
						//right
					BoardModel.getInstance().gameGraph.addArc(10,11,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,2) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(1,2);		
						//top
					BoardModel.getInstance().gameGraph.addArc(10,5,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,2) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(0,1);		
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(10,5,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,2) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(1,1);			
						//lowerRight
					BoardModel.getInstance().gameGraph.addArc(10,5,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,2) as GasketButton).lowerRight = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);			
					
					//11 [1,2]4
						//left
					BoardModel.getInstance().gameGraph.addArc(11,10,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,2) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(0,2);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(11,16,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,2) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);	
						//right
					BoardModel.getInstance().gameGraph.addArc(11,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,2) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);	
						//top
					BoardModel.getInstance().gameGraph.addArc(11,6,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,2) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(1,1);	
					
					//12 [2,2]8
						//left
					BoardModel.getInstance().gameGraph.addArc(12,11,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(1,2);		
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(12,16,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).lowerLeft = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(12,17,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(2,3);			
						//lowerRight
					BoardModel.getInstance().gameGraph.addArc(12,18,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).lowerRight = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);			
						//right
					BoardModel.getInstance().gameGraph.addArc(12,13,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(3,2);			
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(12,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(3,1);			
						//top
					BoardModel.getInstance().gameGraph.addArc(12,7,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(2,1);			
						//upperLeft	
					BoardModel.getInstance().gameGraph.addArc(12,6,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,2) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(1,1);		
					
					//13 [3,2]	4
						//left
					BoardModel.getInstance().gameGraph.addArc(13,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,2) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(13,18,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,2) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);	
						//right
					BoardModel.getInstance().gameGraph.addArc(13,14,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,2) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(4,2);	
						//top
					BoardModel.getInstance().gameGraph.addArc(13,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,2) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(3,1);	
					
					//14 [4,2] 5
						//left
					BoardModel.getInstance().gameGraph.addArc(14,13,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,2) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(3,2);	
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(14,18,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,2) as GasketButton).lowerLeft = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);				
						//bottom
					BoardModel.getInstance().gameGraph.addArc(14,19,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,2) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(4,3);	
						//top
					BoardModel.getInstance().gameGraph.addArc(14,9,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,2) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(4,1);	
						//upperLeft
					BoardModel.getInstance().gameGraph.addArc(14,8,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,2) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(3,1);		
					
					//15 [0,3] 3
						//bottom
					BoardModel.getInstance().gameGraph.addArc(15,20,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,3) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(0,4);	
						//right
					BoardModel.getInstance().gameGraph.addArc(15,16,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,3) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);		
						//top
					BoardModel.getInstance().gameGraph.addArc(15,5,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,3) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(0,2);	
					
					//16 [1,3] 8
						//left
					BoardModel.getInstance().gameGraph.addArc(16,15,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(0,3);		
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(16,20,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).lowerLeft = 
					BoardModel.getInstance().gasketsPosition.gett(0,4);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(16,21,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(1,4);			
						//lowerRight
					BoardModel.getInstance().gameGraph.addArc(16,22,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).lowerRight = 
					BoardModel.getInstance().gasketsPosition.gett(2,4);			
						//right
					BoardModel.getInstance().gameGraph.addArc(16,17,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(2,3);			
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(16,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);			
						//top
					BoardModel.getInstance().gameGraph.addArc(16,11,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(1,2);			
						//upperLeft	
					BoardModel.getInstance().gameGraph.addArc(16,10,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,3) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(0,2);	
					
					//17 [2,3] 4
						//left
					BoardModel.getInstance().gameGraph.addArc(17,16,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,3) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(17,22,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,3) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(2,4);	
						//right
					BoardModel.getInstance().gameGraph.addArc(17,18,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,3) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);	
						//top
					BoardModel.getInstance().gameGraph.addArc(17,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,3) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);
					
					//18 [3,3] 8	
						//left
					BoardModel.getInstance().gameGraph.addArc(18,17,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(2,3);		
						//lowerLeft
					BoardModel.getInstance().gameGraph.addArc(18,22,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).lowerLeft = 
					BoardModel.getInstance().gasketsPosition.gett(2,4);		
						//bottom
					BoardModel.getInstance().gameGraph.addArc(18,23,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(3,4);			
						//lowerRight
					BoardModel.getInstance().gameGraph.addArc(18,24,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).lowerRight = 
					BoardModel.getInstance().gasketsPosition.gett(4,4);			
						//right
					BoardModel.getInstance().gameGraph.addArc(18,19,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(4,3);			
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(18,14,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(4,2);			
						//top
					BoardModel.getInstance().gameGraph.addArc(18,13,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(3,2);			
						//upperLeft	
					BoardModel.getInstance().gameGraph.addArc(18,12,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,3) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(2,2);	
					
					//19 [4,3] 3
						//left
					BoardModel.getInstance().gameGraph.addArc(19,18,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,3) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);			
						//bottom
					BoardModel.getInstance().gameGraph.addArc(19,24,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,3) as GasketButton).bottom = 
					BoardModel.getInstance().gasketsPosition.gett(4,4);	
						//top
					BoardModel.getInstance().gameGraph.addArc(19,14,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,3) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(4,2);	
					
					//20 [0,4] 	3
						//right
					BoardModel.getInstance().gameGraph.addArc(20,21,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,4) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(1,4);	
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(20,16,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,4) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);	
						//top
					BoardModel.getInstance().gameGraph.addArc(20,15,1);
					(BoardModel.getInstance().gasketsPosition.gett(0,4) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(0,3);	
					
					//21 [1,4] 3
						//left
					BoardModel.getInstance().gameGraph.addArc(21,20,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,4) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(0,4);	
						//right 
					BoardModel.getInstance().gameGraph.addArc(21,22,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,4) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(2,4);	
						//top
					BoardModel.getInstance().gameGraph.addArc(21,16,1);
					(BoardModel.getInstance().gasketsPosition.gett(1,4) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);
					
					//22 [2,4] 5
						//left
					BoardModel.getInstance().gameGraph.addArc(22,21,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,4) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(1,4);		
						//right
					BoardModel.getInstance().gameGraph.addArc(22,23,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,4) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(3,4);		
						//upperRight
					BoardModel.getInstance().gameGraph.addArc(22,18,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,4) as GasketButton).upperRight = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);		
						//top
					BoardModel.getInstance().gameGraph.addArc(22,17,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,4) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(2,3);		
						//upperLeft
					BoardModel.getInstance().gameGraph.addArc(22,16,1);
					(BoardModel.getInstance().gasketsPosition.gett(2,4) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(1,3);	
					
					//23 [3,4] 3	
						//left
					BoardModel.getInstance().gameGraph.addArc(23,22,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,4) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(2,4);	
						//right 
					BoardModel.getInstance().gameGraph.addArc(23,24,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,4) as GasketButton).right = 
					BoardModel.getInstance().gasketsPosition.gett(4,4);	
						//top
					BoardModel.getInstance().gameGraph.addArc(23,18,1);
					(BoardModel.getInstance().gasketsPosition.gett(3,4) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);	
					
					//24 [4,4] 2
						//left
					BoardModel.getInstance().gameGraph.addArc(24,23,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,4) as GasketButton).left = 
					BoardModel.getInstance().gasketsPosition.gett(3,4);	
						//top
					BoardModel.getInstance().gameGraph.addArc(24,19,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,4) as GasketButton).top = 
					BoardModel.getInstance().gasketsPosition.gett(4,3);		
						//upperLeft
					BoardModel.getInstance().gameGraph.addArc(24,19,1);
					(BoardModel.getInstance().gasketsPosition.gett(4,4) as GasketButton).upperLeft = 
					BoardModel.getInstance().gasketsPosition.gett(3,3);		
					
					trace("####################BoardGraph graphNode test#####################");
					var iterator:Iterator = BoardModel.getInstance().gameGraph.getIterator();
					var graphNode:GraphNode;
					while(iterator.hasNext())
					{
						graphNode = iterator.data; 
						trace("---------------------------------------------");
						trace("(graphNode.data as GasketButton).name:",(graphNode.data as GasketButton).name,"[",(graphNode.data as GasketButton).position,"]");
						trace("(graphNode.data as GasketButton).left:",(graphNode.data as GasketButton).left);
						trace("(graphNode.data as GasketButton).lowerLeft:",(graphNode.data as GasketButton).lowerLeft);
						trace("(graphNode.data as GasketButton).bottom:",(graphNode.data as GasketButton).bottom);
						trace("(graphNode.data as GasketButton).lowerRight:",(graphNode.data as GasketButton).lowerRight);
						trace("(graphNode.data as GasketButton).right:",(graphNode.data as GasketButton).right);
						trace("(graphNode.data as GasketButton).upperRight:",(graphNode.data as GasketButton).upperRight);
						trace("(graphNode.data as GasketButton).top:",(graphNode.data as GasketButton).top);
						trace("(graphNode.data as GasketButton).upperLeft:",(graphNode.data as GasketButton).upperLeft);
//						trace("iterator.next().data.data:",iterator.next().data.data);
						var r1:Number = NumberUtil.randomNumberWithScope(0,11);
						var r2:Number = NumberUtil.randomNumberWithScope(0,11);
						trace("BoardModel.getInstance().boardGraph.getArc(",r1,r2,":",BoardModel.getInstance().gameGraph.getArc( r1,r2));
						
						
						/*if(AStarLine.find( BoardModel.getInstance().gameGraph,
										   BoardModel.getInstance().gameGraph.nodes[r1],
										   BoardModel.getInstance().gameGraph.nodes[r2] ))
						{
							var paths:LinkedStack = AStarLine.getPath( 
																BoardModel.getInstance().gameGraph.nodes[r1],
																BoardModel.getInstance().gameGraph.nodes[r2]);
							trace("--------AStarLine test func begin-----------");
							trace("Found paths(",r1,"~",r2,"):", paths.dump() );	
							trace("--------AStarLine test func end-------------");
						}		*/		   
						
						iterator.next();	
					}
					
					
					trace("####################BoardGraph graphNode test#####################");
				default:
					break;		
			}
			
			
		}
		
		
	}
}